const pool = require('../db/conn')

// 获取统计数据（学生/教师/课程，过滤已删除）
exports.getStats = async (req, res) => {
  const sql = `
    SELECT 
      (SELECT COUNT(*) FROM rc_student WHERE student_is_delete = 0) AS studentCount,
      (SELECT COUNT(*) FROM rc_teacher WHERE teacher_is_delete = 0) AS teacherCount,
      (SELECT COUNT(*) FROM rc_course  WHERE course_is_delete  = 0) AS courseCount
  `
  const conn = await pool.getConnection()
  const [rows] = await conn.execute(sql)
  conn.release()
  const data = rows && rows[0] ? rows[0] : { studentCount: 0, teacherCount: 0, courseCount: 0 }
  res.sendResult(data, 200, '请求成功')
}
